/* @(#)GSOrderDeptInfoAction.java    V0.1
 *
 * Project: GSdevelop
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   owen         2006-2-16
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.util.ArrayList;
import java.util.HashMap;

import com.hitrust.gs.bean.GSOrganizationBean;
import com.hitrust.gs.business.GSOrganizationProcessor;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;

/**
 * 
 */
public class GSOrderDeptInfoAction extends GSBaseAction{

    public String execute(GSBaseForm aForm) throws Exception {
        
        
        //取得上级组织机构编号
        ArrayList tOraganization=GSOrganizationProcessor.queryManageUpOrg();
        aForm.getRequest().setAttribute("Oraganization",tOraganization);
        
        //取得所有组织机构编号
        ArrayList tAllOraganization = GSOrganizationProcessor.queryManageOrg("","");
        aForm.getRequest().setAttribute("AllOraganization",tAllOraganization);
        HashMap tMap = new HashMap();
        
        if(tOraganization != null ){
            for(int i=0; i<tOraganization.size(); i++){
                //上级组织机构编号
                GSOrganizationBean tGSOrganizationBean = (GSOrganizationBean)tOraganization.get(i);
                
                if(tAllOraganization != null){
                    ArrayList tList1 = new ArrayList();
                    for(int j=0; j<tAllOraganization.size();j++){
                        //二级产品种类
                        
                        GSOrganizationBean tGSOrganizationBean1 = (GSOrganizationBean)tAllOraganization.get(j);
                        String level1=tGSOrganizationBean.getGs_org_id();
                        String level2=tGSOrganizationBean1.getGs_upper_orgId();
                        String orgid=tGSOrganizationBean1.getGs_org_id();
                       
                        if(level1.equals("0000")){
                           //判断巴士物资的下拉
                          if(level1.equals(level2)&&orgid.substring(0,2).equals("00")){
                             tList1.add(tGSOrganizationBean1);
                          }
                        }
                        else{
                            //String a=tGSOrganizationBean.getGs_org_id().substring(0,2);
                            //String b=tGSOrganizationBean1.getGs_org_id().substring(0,2);
                            //String c=tGSOrganizationBean1.getGs_upper_orgId();
                           //运营公司的下拉判断
                            if(level1.equals(level2)||orgid.equals(level1)){
                                tList1.add(tGSOrganizationBean1);
                            }
                        }
                      
                    }
                    if(tList1.size() > 0)
                        tMap.put(""+tGSOrganizationBean.getGs_org_id(),tList1);
                }
            }
            aForm.getRequest().setAttribute("Organization2",tMap);

        }  
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
